package com.esri.core.geometry;

import com.esri.core.geometry.Geometry;
import com.esri.core.geometry.GeometryEngine;
import com.esri.core.geometry.Operator;
import com.esri.core.internal.util.d;
import com.github.mikephil.charting.utils.Utils;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.codehaus.jackson.JsonParser;

/* loaded from: classes.dex */
public class GeometryEngineCore {
    private static OperatorFactoryLocal a = OperatorFactoryLocal.getInstance();
    private static final String b = "Input Spatial Reference can't be null.";
    private static final String c = "Input geometry can't be null.";
    private static final String d = "Input geometry can't be a Line.";

    static native byte[] nativeBuffer(byte[] bArr, int i, String str, double d2);

    static native byte[][] nativeBuffer(byte[][] bArr, int i, String str, double[] dArr, boolean z);

    static native byte[] nativeClip(byte[] bArr, double d2, double d3, double d4, double d5, int i, String str);

    static native boolean nativeContains(byte[] bArr, byte[] bArr2, int i, String str);

    static native boolean nativeCrosses(byte[] bArr, byte[] bArr2, int i, String str);

    static native byte[] nativeDifference(byte[] bArr, byte[] bArr2, int i, String str);

    static native double nativeDistance(byte[] bArr, byte[] bArr2, int i, String str);

    static native boolean nativeEquals(byte[] bArr, byte[] bArr2, int i, String str);

    static native double nativeGeodesicArea(byte[] bArr, int i, String str, int i2);

    static native double nativeGeodesicDistance(double d2, double d3, double d4, double d5, int i, String str, int i2);

    static native byte[] nativeGeodesicEllipse(double d2, double d3, double d4, double d5, double d6, int i, String str, int i2, int i3);

    static native byte[] nativeGeodesicGeometry(byte[] bArr, int i, String str, double d2, int i2);

    static native byte[][] nativeGeodesicMove(double[] dArr, double[] dArr2, int i, String str, double d2, double d3, int i2);

    static native byte[][] nativeGeodesicOffset(byte[][] bArr, int i, String str, double d2, int i2, double d3, double d4, Object obj);

    static native byte[] nativeGeodesicSector(double d2, double d3, int i, String str, double d4, double d5, double d6, double d7, double d8, double d9, double d10, int i2);

    static native double nativeGeodeticLength(byte[] bArr, int i, String str, int i2);

    public static native String nativeGetGeoTx(int i, String str, boolean z);

    static native double[] nativeGetNearestCoordinate(byte[] bArr, double d2, double d3, boolean z);

    static native double[] nativeGetNearestVertex(byte[] bArr, double d2, double d3);

    static native double[][] nativeGetNearestVertices(byte[] bArr, double d2, double d3, double d4, int i);

    static native int nativeGetTransformationWkid(String str);

    public static native String nativeGetTransformationWktxt(int i);

    static native String[] nativeGetTransformations(int i, String str, int i2, String str2, double d2, double d3, double d4, double d5, int i3);

    static native byte[] nativeIntersection(byte[] bArr, byte[] bArr2, int i, String str);

    static native byte[][] nativeIntersection(byte[][] bArr, byte[] bArr2, int i, String str);

    static native boolean nativeIntersects(byte[] bArr, byte[] bArr2, int i, String str);

    static native boolean nativeIsSimpleAsFeature(byte[] bArr, int i, String str);

    static native double[] nativeLablePointForPolygon(byte[] bArr, int i, String str);

    static native byte[] nativeNormalizeCentralMeridian(byte[] bArr, int i, String str);

    static native byte[] nativeProject(byte[] bArr, int i, String str, int i2, String str2, String str3);

    static native double[] nativeProjectEnvelope(double d2, double d3, double d4, double d5, int i, String str, int i2, String str2, String str3);

    static native double[] nativeProjectPoint(double d2, double d3, int i, String str, int i2, String str2, String str3);

    static native byte[] nativeSimplify(byte[] bArr, int i, String str);

    static native boolean nativeTouches(byte[] bArr, byte[] bArr2, int i, String str);

    static native byte[] nativeUnion(byte[][] bArr, int i, String str);

    static native boolean nativeWithin(byte[] bArr, byte[] bArr2, int i, String str);

    GeometryEngineCore() {
    }

    public static final Geometry project(Geometry geometry, SpatialReference spatialReference, SpatialReference spatialReference2) {
        return project(geometry, spatialReference, spatialReference2, null);
    }

    public static final Point project(double d2, double d3, SpatialReference spatialReference) {
        if (spatialReference == null) {
            return new Point(d2, d3);
        }
        double[] nativeProjectPoint = nativeProjectPoint(d2, d3, SpatialReference.WKID_WGS84, null, spatialReference.getID(), spatialReference.getText(), null);
        if (nativeProjectPoint == null || nativeProjectPoint.length != 2) {
            return null;
        }
        return new Point(nativeProjectPoint[0], nativeProjectPoint[1]);
    }

    public static final Geometry project(Geometry geometry, SpatialReference spatialReference, SpatialReference spatialReference2, CompositeGeographicTransformation compositeGeographicTransformation) {
        if (spatialReference == null || spatialReference2 == null) {
            return geometry;
        }
        String a2 = (compositeGeographicTransformation == null || compositeGeographicTransformation.getTransformations().isEmpty()) ? null : compositeGeographicTransformation.a();
        if (geometry.getType().equals(Geometry.Type.POINT)) {
            Point point = (Point) geometry;
            double[] nativeProjectPoint = nativeProjectPoint(point.getX(), point.getY(), spatialReference.getID(), spatialReference.getText(), spatialReference2.getID(), spatialReference2.getText(), a2);
            if (nativeProjectPoint == null || nativeProjectPoint.length != 2) {
                return null;
            }
            return new Point(nativeProjectPoint[0], nativeProjectPoint[1]);
        } else if (geometry.getType().equals(Geometry.Type.ENVELOPE)) {
            Envelope envelope = (Envelope) geometry;
            double[] nativeProjectEnvelope = nativeProjectEnvelope(envelope.getXMin(), envelope.getYMin(), envelope.getXMax(), envelope.getYMax(), spatialReference.getID(), spatialReference.getText(), spatialReference2.getID(), spatialReference2.getText(), a2);
            if (nativeProjectEnvelope == null || nativeProjectEnvelope.length != 4) {
                return null;
            }
            return new Envelope(nativeProjectEnvelope[0], nativeProjectEnvelope[1], nativeProjectEnvelope[2], nativeProjectEnvelope[3]);
        } else {
            byte[] nativeProject = nativeProject(geometryToEsriShape(geometry), spatialReference.getID(), spatialReference.getText(), spatialReference2.getID(), spatialReference2.getText(), a2);
            if (nativeProject != null) {
                return geometryFromEsriShape(nativeProject, geometry.getType());
            }
            return null;
        }
    }

    public static List<CompositeGeographicTransformation> getTransformations(SpatialReference spatialReference, SpatialReference spatialReference2, Envelope envelope, int i) {
        if (spatialReference == null || spatialReference2 == null) {
            throw new IllegalArgumentException(b);
        }
        if (envelope != null) {
            if (i < 0) {
                throw new IllegalArgumentException("Max entries can't be negative.");
            }
            String[] nativeGetTransformations = nativeGetTransformations(spatialReference.getID(), spatialReference.getText(), spatialReference2.getID(), spatialReference2.getText(), envelope.getXMin(), envelope.getYMin(), envelope.getXMax(), envelope.getYMax(), i);
            ArrayList arrayList = new ArrayList();
            if (nativeGetTransformations != null) {
                JsonParser jsonParser = null;
                try {
                    try {
                        for (String str : nativeGetTransformations) {
                            jsonParser = d.c(str);
                            CompositeGeographicTransformation a2 = CompositeGeographicTransformation.a(jsonParser);
                            if (a2 != null) {
                                arrayList.add(a2);
                            }
                        }
                        if (jsonParser != null) {
                            try {
                                jsonParser.close();
                            } catch (IOException e) {
                                throw new RuntimeException(e);
                            }
                        }
                    } catch (Throwable th) {
                        if (jsonParser != null) {
                            try {
                                jsonParser.close();
                            } catch (IOException e2) {
                                throw new RuntimeException(e2);
                            }
                        }
                        throw th;
                    }
                } catch (Exception e3) {
                    throw new RuntimeException(e3);
                }
            }
            return arrayList;
        }
        throw new IllegalArgumentException("Input extent can't be null.");
    }

    public static final MapGeometry jsonToGeometry(JsonParser jsonParser) {
        return ((OperatorImportFromJson) a.getOperator(Operator.Type.IMPORT_MAP_GEOMETRY_FROM_JSON)).execute(Geometry.Type.UNKNOWN, jsonParser);
    }

    public static final String geometryToJson(SpatialReference spatialReference, Geometry geometry) {
        return ((OperatorExportToJson) a.getOperator(Operator.Type.EXPORT_TO_JSON)).execute(spatialReference, geometry);
    }

    public static final Geometry geometryFromEsriShape(byte[] bArr, Geometry.Type type) {
        return ((OperatorImportFromESRIShape) a.getOperator(Operator.Type.IMPORT_FROM_ESRI_SHAPE)).execute(2, type, ByteBuffer.wrap(bArr).order(ByteOrder.LITTLE_ENDIAN));
    }

    public static final byte[] geometryToEsriShape(Geometry geometry) {
        if (geometry == null) {
            throw new IllegalArgumentException();
        }
        return ((OperatorExportToESRIShape) a.getOperator(Operator.Type.EXPORT_TO_ESRI_SHAPE)).execute(64, geometry).array();
    }

    public static final Geometry union(Geometry[] geometryArr, SpatialReference spatialReference) {
        String str;
        if (geometryArr == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        } else {
            str = null;
        }
        byte[] nativeUnion = nativeUnion(a(geometryArr), i, str);
        if (nativeUnion != null) {
            return geometryFromEsriShape(nativeUnion, Geometry.Type.UNKNOWN);
        }
        return null;
    }

    public static final Geometry difference(Geometry geometry, Geometry geometry2, SpatialReference spatialReference) {
        String str;
        if (geometry == null || geometry2 == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        } else {
            str = null;
        }
        byte[] nativeDifference = nativeDifference(geometryToEsriShape(geometry), geometryToEsriShape(geometry2), i, str);
        if (nativeDifference != null) {
            return geometryFromEsriShape(nativeDifference, Geometry.Type.UNKNOWN);
        }
        return null;
    }

    public static final boolean equals(Geometry geometry, Geometry geometry2, SpatialReference spatialReference) {
        int i;
        String str;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        } else {
            i = -1;
            str = null;
        }
        return nativeEquals(geometryToEsriShape(geometry), geometryToEsriShape(geometry2), i, str);
    }

    public static final Geometry[] a(Geometry[] geometryArr, Geometry geometry, SpatialReference spatialReference) {
        if (geometryArr == null || geometry == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        String str = null;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        }
        return a(nativeIntersection(a(geometryArr), geometryToEsriShape(geometry), i, str), Geometry.Type.UNKNOWN);
    }

    public static final Geometry intersect(Geometry geometry, Geometry geometry2, SpatialReference spatialReference) {
        String str;
        if (geometry == null || geometry2 == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        } else {
            str = null;
        }
        byte[] nativeIntersection = nativeIntersection(geometryToEsriShape(geometry), geometryToEsriShape(geometry2), i, str);
        if (nativeIntersection != null) {
            return geometryFromEsriShape(nativeIntersection, Geometry.Type.UNKNOWN);
        }
        return null;
    }

    public static final boolean within(Geometry geometry, Geometry geometry2, SpatialReference spatialReference) {
        if (geometry == null || geometry2 == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        String str = null;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        }
        return nativeWithin(geometryToEsriShape(geometry), geometryToEsriShape(geometry2), i, str);
    }

    public static final boolean intersects(Geometry geometry, Geometry geometry2, SpatialReference spatialReference) {
        if (geometry == null || geometry2 == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        String str = null;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        }
        return nativeIntersects(geometryToEsriShape(geometry), geometryToEsriShape(geometry2), i, str);
    }

    public static final boolean contains(Geometry geometry, Geometry geometry2, SpatialReference spatialReference) {
        if (geometry == null || geometry2 == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        String str = null;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        }
        return nativeContains(geometryToEsriShape(geometry), geometryToEsriShape(geometry2), i, str);
    }

    public static final boolean crosses(Geometry geometry, Geometry geometry2, SpatialReference spatialReference) {
        if (geometry == null || geometry2 == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        String str = null;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        }
        return nativeCrosses(geometryToEsriShape(geometry), geometryToEsriShape(geometry2), i, str);
    }

    public static final boolean touches(Geometry geometry, Geometry geometry2, SpatialReference spatialReference) {
        if (geometry == null || geometry2 == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        String str = null;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        }
        return nativeTouches(geometryToEsriShape(geometry), geometryToEsriShape(geometry2), i, str);
    }

    public static final double distance(Geometry geometry, Geometry geometry2, SpatialReference spatialReference) {
        if (geometry == null || geometry2 == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        String str = null;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        }
        return nativeDistance(geometryToEsriShape(geometry), geometryToEsriShape(geometry2), i, str);
    }

    public static final Geometry clip(Geometry geometry, Envelope envelope, SpatialReference spatialReference) {
        String str;
        int i;
        if (geometry == null || envelope == null || envelope.isEmpty()) {
            return geometry;
        }
        if (spatialReference != null) {
            int id = spatialReference.getID();
            str = spatialReference.getText();
            i = id;
        } else {
            str = null;
            i = -1;
        }
        byte[] nativeClip = nativeClip(geometryToEsriShape(geometry), envelope.getXMin(), envelope.getYMin(), envelope.getXMax(), envelope.getYMax(), i, str);
        if (nativeClip != null) {
            return geometryFromEsriShape(nativeClip, Geometry.Type.UNKNOWN);
        }
        return null;
    }

    public static final Polygon[] buffer(Geometry[] geometryArr, SpatialReference spatialReference, double[] dArr, Unit unit, boolean z) {
        String str;
        ArrayList arrayList;
        if (spatialReference != null) {
            Unit unit2 = spatialReference.getUnit();
            if (unit != null && unit2.getID() != unit.getID()) {
                if (unit2.getUnitType() != unit.getUnitType()) {
                    throw new IllegalArgumentException();
                }
                double[] dArr2 = new double[dArr.length];
                Unit.convertUnits(dArr, dArr.length, unit, unit2, dArr2);
                dArr = dArr2;
            }
        } else if (unit != null) {
            throw new IllegalArgumentException();
        }
        int i = -1;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        } else {
            str = null;
        }
        byte[][] nativeBuffer = nativeBuffer(a(geometryArr), i, str, dArr, z);
        if (nativeBuffer != null) {
            arrayList = new ArrayList();
            for (int i2 = 0; i2 < nativeBuffer.length; i2++) {
                if (nativeBuffer[i2] != null) {
                    arrayList.add((Polygon) geometryFromEsriShape(nativeBuffer[i2], Geometry.Type.POLYGON));
                }
            }
        } else {
            arrayList = null;
        }
        if (arrayList != null) {
            return (Polygon[]) arrayList.toArray(new Polygon[0]);
        }
        return null;
    }

    public static final Polygon buffer(Geometry geometry, SpatialReference spatialReference, double d2, Unit unit) {
        String str;
        if (spatialReference != null) {
            Unit unit2 = spatialReference.getUnit();
            if (unit != null && unit2.getID() != unit.getID()) {
                if (unit2.getUnitType() != unit.getUnitType()) {
                    throw new GeometryException("The input unit and the spatial reference unit are not of the same unit type. ie Linear vs. Angular");
                }
                d2 = Unit.convertUnits(d2, unit, unit2);
            }
        } else if (unit != null) {
            throw new IllegalArgumentException();
        }
        int i = -1;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        } else {
            str = null;
        }
        byte[] nativeBuffer = nativeBuffer(geometryToEsriShape(geometry), i, str, d2);
        if (nativeBuffer != null) {
            return (Polygon) geometryFromEsriShape(nativeBuffer, Geometry.Type.POLYGON);
        }
        return null;
    }

    public static final Proximity2DResult getNearestCoordinate(Geometry geometry, Point point, boolean z) {
        if (geometry == null || point == null) {
            throw new IllegalArgumentException(c);
        }
        double[] nativeGetNearestCoordinate = nativeGetNearestCoordinate(geometryToEsriShape(geometry), point.getX(), point.getY(), z);
        if (nativeGetNearestCoordinate == null || nativeGetNearestCoordinate.length != 4) {
            return null;
        }
        Proximity2DResult proximity2DResult = new Proximity2DResult();
        proximity2DResult.a.x = nativeGetNearestCoordinate[0];
        proximity2DResult.a.y = nativeGetNearestCoordinate[1];
        proximity2DResult.b = (int) nativeGetNearestCoordinate[2];
        proximity2DResult.c = nativeGetNearestCoordinate[3];
        return proximity2DResult;
    }

    public static final Proximity2DResult getNearestVertex(Geometry geometry, Point point) {
        if (geometry == null || point == null) {
            throw new IllegalArgumentException(c);
        }
        double[] nativeGetNearestVertex = nativeGetNearestVertex(geometryToEsriShape(geometry), point.getX(), point.getY());
        if (nativeGetNearestVertex == null || nativeGetNearestVertex.length != 4) {
            return null;
        }
        Proximity2DResult proximity2DResult = new Proximity2DResult();
        proximity2DResult.a.x = nativeGetNearestVertex[0];
        proximity2DResult.a.y = nativeGetNearestVertex[1];
        proximity2DResult.b = (int) nativeGetNearestVertex[2];
        proximity2DResult.c = nativeGetNearestVertex[3];
        return proximity2DResult;
    }

    public static final Proximity2DResult[] getNearestVertices(Geometry geometry, Point point, double d2, int i) {
        Proximity2DResult proximity2DResult;
        if (geometry == null || point == null) {
            throw new IllegalArgumentException(c);
        }
        double[][] nativeGetNearestVertices = nativeGetNearestVertices(geometryToEsriShape(geometry), point.getX(), point.getY(), d2, i);
        if (nativeGetNearestVertices != null) {
            Proximity2DResult[] proximity2DResultArr = new Proximity2DResult[nativeGetNearestVertices.length];
            int length = nativeGetNearestVertices.length;
            int i2 = 0;
            int i3 = 0;
            while (i2 < length) {
                double[] dArr = nativeGetNearestVertices[i2];
                if (dArr == null || dArr.length != 4) {
                    proximity2DResult = null;
                } else {
                    proximity2DResult = new Proximity2DResult();
                    proximity2DResult.a.x = dArr[0];
                    proximity2DResult.a.y = dArr[1];
                    proximity2DResult.b = (int) dArr[2];
                    proximity2DResult.c = dArr[3];
                }
                proximity2DResultArr[i3] = proximity2DResult;
                i2++;
                i3++;
            }
            return proximity2DResultArr;
        }
        return null;
    }

    public static final Geometry simplify(Geometry geometry, SpatialReference spatialReference) {
        int i;
        String str;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        } else {
            i = -1;
            str = null;
        }
        byte[] nativeSimplify = nativeSimplify(geometryToEsriShape(geometry), i, str);
        if (nativeSimplify != null) {
            return geometryFromEsriShape(nativeSimplify, Geometry.Type.UNKNOWN);
        }
        return null;
    }

    public static boolean a(Geometry geometry, SpatialReference spatialReference) {
        if (geometry == null) {
            throw new IllegalArgumentException(c);
        }
        int i = -1;
        String str = null;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        }
        return nativeIsSimpleAsFeature(geometryToEsriShape(geometry), i, str);
    }

    public static Geometry normalizeCentralMeridian(Geometry geometry, SpatialReference spatialReference) {
        if (geometry != null) {
            if (spatialReference == null) {
                throw new IllegalArgumentException(b);
            }
            if (geometry instanceof Line) {
                throw new IllegalArgumentException(d);
            }
            byte[] nativeNormalizeCentralMeridian = nativeNormalizeCentralMeridian(geometryToEsriShape(geometry), spatialReference.getID(), spatialReference.getText());
            if (nativeNormalizeCentralMeridian != null) {
                return geometryFromEsriShape(nativeNormalizeCentralMeridian, Geometry.Type.UNKNOWN);
            }
            return null;
        }
        throw new IllegalArgumentException(c);
    }

    public static double geodesicArea(Geometry geometry, SpatialReference spatialReference, AreaUnit areaUnit) {
        if (geometry != null) {
            if (spatialReference == null) {
                throw new IllegalArgumentException(b);
            }
            double nativeGeodesicArea = nativeGeodesicArea(geometryToEsriShape(geometry), spatialReference.getID(), spatialReference.getText(), 0);
            return areaUnit != null ? areaUnit.convertFromSquareMeters(nativeGeodesicArea) : nativeGeodesicArea;
        }
        throw new IllegalArgumentException(c);
    }

    public static final double geodesicLength(Geometry geometry, SpatialReference spatialReference, LinearUnit linearUnit) {
        int i;
        String str;
        if (spatialReference != null) {
            i = spatialReference.getID();
            str = spatialReference.getText();
        } else {
            i = -1;
            str = null;
        }
        double nativeGeodeticLength = nativeGeodeticLength(geometryToEsriShape(geometry), i, str, 0);
        return linearUnit != null ? linearUnit.convertFromMeters(nativeGeodeticLength) : nativeGeodeticLength;
    }

    public static List<Geometry> geodesicOffset(List<Geometry> list, SpatialReference spatialReference, double d2, GeometryEngine.JoinType joinType, double d3, double d4, ProgressTracker progressTracker) {
        String str;
        int i;
        if (list != null) {
            if (joinType != null) {
                if (d2 == Utils.DOUBLE_EPSILON) {
                    return list;
                }
                if (spatialReference != null) {
                    i = spatialReference.getID();
                    str = spatialReference.getText();
                } else {
                    str = null;
                    i = -1;
                }
                return Arrays.asList(a(nativeGeodesicOffset(a((Geometry[]) list.toArray(new Geometry[list.size()])), i, str, d2, joinType.a(), d3, d4, progressTracker), Geometry.Type.UNKNOWN));
            }
            throw new IllegalArgumentException("Join type can't be null.");
        }
        throw new IllegalArgumentException(c);
    }

    public static Geometry geodesicDensifyGeometry(Geometry geometry, SpatialReference spatialReference, double d2, LinearUnit linearUnit) {
        if (geometry != null) {
            if (spatialReference != null) {
                if (d2 < 1.0d) {
                    throw new IllegalArgumentException("Input maximum segment length can't be 0 or negative.");
                }
                if ((geometry instanceof Point) || (geometry instanceof MultiPoint)) {
                    return geometry;
                }
                byte[] geometryToEsriShape = geometryToEsriShape(geometry);
                int id = spatialReference.getID();
                String text = spatialReference.getText();
                if (linearUnit != null) {
                    d2 = linearUnit.convertToMeters(d2);
                }
                return geometryFromEsriShape(nativeGeodesicGeometry(geometryToEsriShape, id, text, d2, 0), Geometry.Type.UNKNOWN);
            }
            throw new IllegalArgumentException(b);
        }
        throw new IllegalArgumentException(c);
    }

    public static double geodesicDistance(Point point, Point point2, SpatialReference spatialReference, LinearUnit linearUnit) {
        if (point == null || point2 == null) {
            throw new IllegalArgumentException(c);
        }
        if (spatialReference == null) {
            throw new IllegalArgumentException(b);
        }
        double nativeGeodesicDistance = nativeGeodesicDistance(point.getX(), point.getY(), point2.getX(), point2.getY(), spatialReference.getID(), spatialReference.getText(), 0);
        return linearUnit != null ? linearUnit.convertFromMeters(nativeGeodesicDistance) : nativeGeodesicDistance;
    }

    public static Geometry geodesicEllipse(Point point, SpatialReference spatialReference, double d2, double d3, double d4, int i, LinearUnit linearUnit, Geometry.Type type) {
        double d5 = d2;
        if (point != null) {
            if (d5 < 1.0d || d3 < 1.0d) {
                throw new IllegalArgumentException("Input length of any axis can't be 0 or negative.");
            }
            if (spatialReference != null) {
                if (i >= 1) {
                    if (type == null) {
                        throw new IllegalArgumentException("Input output type can't be null.");
                    }
                    if (type != Geometry.Type.MULTIPOINT && type != Geometry.Type.POLYLINE && type != Geometry.Type.POLYGON) {
                        throw new IllegalArgumentException("Invalid output type. It should be one of MULTIPOINT, POLYLINE, or POLYGON.");
                    }
                    int id = spatialReference.getID();
                    String text = spatialReference.getText();
                    double x = point.getX();
                    double y = point.getY();
                    if (linearUnit != null) {
                        d5 = linearUnit.convertToMeters(d5);
                    }
                    return geometryFromEsriShape(nativeGeodesicEllipse(x, y, d5, linearUnit != null ? linearUnit.convertToMeters(d3) : d3, Math.toRadians(d4), id, text, i, type.value()), Geometry.Type.UNKNOWN);
                }
                throw new IllegalArgumentException("Input point count can't be 0 or negative.");
            }
            throw new IllegalArgumentException(b);
        }
        throw new IllegalArgumentException(c);
    }

    public static List<Point> geodesicMove(List<Point> list, SpatialReference spatialReference, double d2, LinearUnit linearUnit, double d3) {
        if (list != null) {
            if (spatialReference == null) {
                throw new IllegalArgumentException(b);
            }
            if (list.isEmpty()) {
                return new ArrayList();
            }
            double[] dArr = new double[list.size()];
            double[] dArr2 = new double[list.size()];
            int i = 0;
            for (Point point : list) {
                if (point == null) {
                    throw new IllegalArgumentException(c);
                }
                dArr[i] = point.getX();
                dArr2[i] = point.getY();
                i++;
            }
            return Arrays.asList(a(nativeGeodesicMove(dArr, dArr2, spatialReference.getID(), spatialReference.getText(), linearUnit != null ? linearUnit.convertToMeters(d2) : d2, Math.toRadians(d3), 0)));
        }
        throw new IllegalArgumentException(c);
    }

    public static Geometry geodesicSector(Point point, SpatialReference spatialReference, double d2, double d3, double d4, double d5, double d6, double d7, double d8, LinearUnit linearUnit, Geometry.Type type) {
        double d9 = d2;
        double d10 = d3;
        double d11 = d7;
        double d12 = d8;
        if (point != null) {
            if (d9 < 1.0d || d10 < 1.0d) {
                throw new IllegalArgumentException("Input length of any axis can't be 0 or negative.");
            }
            if (spatialReference != null) {
                if (d11 < 1.0d || d12 < 1.0d) {
                    throw new IllegalArgumentException("Input arc or radius length can't be 0 or negative.");
                }
                if (type == null) {
                    throw new IllegalArgumentException("Input output type can't be null.");
                }
                if (type != Geometry.Type.MULTIPOINT && type != Geometry.Type.POLYLINE && type != Geometry.Type.POLYGON) {
                    throw new IllegalArgumentException("Invalid output type. It should be one of MULTIPOINT, POLYLINE, or POLYGON.");
                }
                int id = spatialReference.getID();
                String text = spatialReference.getText();
                if (linearUnit != null) {
                    d9 = linearUnit.convertToMeters(d9);
                    d10 = linearUnit.convertToMeters(d10);
                    d11 = linearUnit.convertToMeters(d11);
                    d12 = linearUnit.convertToMeters(d12);
                }
                return geometryFromEsriShape(nativeGeodesicSector(point.getX(), point.getY(), id, text, d9, d10, Math.toRadians(d4), Math.toRadians(d5), Math.toRadians(d6), d11, d12, type.value()), type);
            }
            throw new IllegalArgumentException(b);
        }
        throw new IllegalArgumentException(c);
    }

    private static Point[] a(byte[][] bArr) {
        if (bArr != null) {
            Point[] pointArr = new Point[bArr.length];
            for (int i = 0; i < bArr.length; i++) {
                if (bArr[i] != null) {
                    pointArr[i] = (Point) geometryFromEsriShape(bArr[i], Geometry.Type.POINT);
                }
            }
            return pointArr;
        }
        return null;
    }

    private static Geometry[] a(byte[][] bArr, Geometry.Type type) {
        if (bArr != null) {
            Geometry[] geometryArr = new Geometry[bArr.length];
            for (int i = 0; i < bArr.length; i++) {
                if (bArr[i] != null) {
                    geometryArr[i] = geometryFromEsriShape(bArr[i], type);
                }
            }
            return geometryArr;
        }
        return null;
    }

    public static Point lablePointForPolygon(Polygon polygon, SpatialReference spatialReference) {
        double[] nativeLablePointForPolygon;
        byte[] geometryToEsriShape = geometryToEsriShape(polygon);
        if (geometryToEsriShape == null || (nativeLablePointForPolygon = nativeLablePointForPolygon(geometryToEsriShape, spatialReference.getID(), spatialReference.getText())) == null || nativeLablePointForPolygon.length != 2) {
            return null;
        }
        return new Point(nativeLablePointForPolygon[0], nativeLablePointForPolygon[1]);
    }

    private static byte[][] a(Geometry[] geometryArr) {
        byte[][] bArr = new byte[geometryArr.length];
        for (int i = 0; i < geometryArr.length; i++) {
            if (geometryArr[i] != null) {
                bArr[i] = geometryToEsriShape(geometryArr[i]);
            }
        }
        return bArr;
    }
}
